import { ref } from 'vue'
import type { DataIndex } from '@/core/enums/name'
import { ComboPriceNameEnum, OnLinePeriodEnum } from '@/core/enums/name'
import { PlatformEnum } from '@/core/enums/platform'
import { onLinePeriodReverseMap } from '@/core/mapper/priceSheet'
import type { PriceVector } from '@/core/interfaces/priceTable'

export type Coordinates = [number, DataIndex] | []

export function usePriceCoordinates() {
  const baiduCoordinates = ref<Coordinates>([])
  const qihu360Coordinates = ref<Coordinates>([])

  function setBaiduCoordinates(coordinates: Coordinates) {
    const [x, y] = coordinates
    baiduCoordinates.value = [x!, y!]
  }

  function set360Coordinates(coordinates: Coordinates) {
    const [x, y] = coordinates
    qihu360Coordinates.value = [x!, y!]
  }

  function resetCoordinates() {
    baiduCoordinates.value = []
    qihu360Coordinates.value = []
  }

  function makeCoordinates(
    comboPriceName: ComboPriceNameEnum,
    onLinePeriodKey: OnLinePeriodEnum,
    clientType: PlatformEnum
  ): Coordinates {
    // const { YEAR, HALF_YEAR, QUARTET, MONTH } = ComboPriceNameEnum
    const { YEAR, HALF_YEAR, QUARTET, MONTH, TwoYEAR } = ComboPriceNameEnum
    const rowIndex = [YEAR, HALF_YEAR, QUARTET, MONTH, TwoYEAR].indexOf(comboPriceName)
    // const rowIndex = [YEAR, HALF_YEAR, QUARTET, MONTH].indexOf(comboPriceName)
    const onLinePeriod = onLinePeriodReverseMap[onLinePeriodKey]
    const platform = PlatformEnum[clientType!]

    return [rowIndex, `${platform.toLowerCase()}${onLinePeriod}` as PriceVector['dataIndex']]
  }

  return {
    baiduCoordinates,
    qihu360Coordinates,
    resetCoordinates,
    makeCoordinates,
    setBaiduCoordinates,
    set360Coordinates
  }
}
